<html>
<head><meta charset="utf-8"><title>Chalk solver caching · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html">Chalk solver caching</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="189925503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189925503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189925503">(Mar 06 2020 at 19:21)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> I'm trying out what happens if we just don't cache the solver and recreate it for every trait query. It feels much faster during editing, and seems to be only slightly slower (if at all) in analysis-stats</p>



<a name="189926406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926406">(Mar 06 2020 at 19:33)</a>:</h4>
<p>hm, lol?</p>



<a name="189926602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926602">(Mar 06 2020 at 19:35)</a>:</h4>
<p>So, the difference is that:</p>
<ul>
<li>we don't use chalk's internal caches across queries</li>
<li>we don't store salsa's metadata?</li>
</ul>



<a name="189926662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926662">(Mar 06 2020 at 19:36)</a>:</h4>
<p>I wonder if the sweet spot is creating a solver per inference context?</p>



<a name="189926888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926888">(Mar 06 2020 at 19:39)</a>:</h4>
<p>not sure what you mean by </p>
<blockquote>
<p>we don't store salsa's metadata?</p>
</blockquote>



<a name="189926916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926916">(Mar 06 2020 at 19:40)</a>:</h4>
<p>it does mean we actually have clean dependency information for each trait query, and don't have to redo all of them every time something changes</p>



<a name="189926972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926972">(Mar 06 2020 at 19:40)</a>:</h4>
<p>also another benefit would be that we can actually run trait queries in parallel, I guess</p>



<a name="189926990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189926990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189926990">(Mar 06 2020 at 19:40)</a>:</h4>
<p>ahhhh</p>



<a name="189927036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189927036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189927036">(Mar 06 2020 at 19:41)</a>:</h4>
<p>right, so the <code>trait_solver</code> query is no longer  volatile, and <code>trait_solve</code> q can actually be usefully cache!</p>



<a name="189927056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189927056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189927056">(Mar 06 2020 at 19:41)</a>:</h4>
<p>and presumably the Chalk-internal caching isn't <em>that</em> huge of a win (assuming most solution are actually pretty shallow)</p>



<a name="189927118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189927118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189927118">(Mar 06 2020 at 19:42)</a>:</h4>
<p><strong>and</strong> this also should fix the problem of analysis-statis OOMing on substrate repo due to chalk being big</p>



<a name="189927390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189927390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189927390">(Mar 06 2020 at 19:45)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> could you repeat <a href="https://github.com/rust-analyzer/rust-analyzer/issues/2945" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/2945">https://github.com/rust-analyzer/rust-analyzer/issues/2945</a> with your patch?</p>



<a name="189927413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189927413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189927413">(Mar 06 2020 at 19:45)</a>:</h4>
<p>sure</p>



<a name="189939062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189939062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189939062">(Mar 06 2020 at 22:02)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> it gets killed after ca. 75%, with ca. 28G resident memory :(</p>



<a name="189941737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189941737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189941737">(Mar 06 2020 at 22:38)</a>:</h4>
<p>Hm, I am running it on substrate, and I have a feeling that it doesn't get to chalk at all</p>



<a name="189941773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189941773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189941773">(Mar 06 2020 at 22:38)</a>:</h4>
<p>Ie, I am seeing two "name resolution is stuck" errors (and we've recently bumped the limit there a lot)</p>



<a name="189941796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189941796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189941796">(Mar 06 2020 at 22:39)</a>:</h4>
<p>which reminds me that I want to rewrite our name resolution loop (which is basically my permanent state?)</p>



<a name="189942401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189942401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189942401">(Mar 06 2020 at 22:49)</a>:</h4>
<p>Wow, it feels a bunch faster indeed</p>



<a name="189942510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189942510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189942510">(Mar 06 2020 at 22:50)</a>:</h4>
<blockquote>
<p>also another benefit would be that we can actually run trait queries in parallel, I guess</p>
</blockquote>
<p>A good start might be to add <code>-j</code> flag to <code>analysis-stats</code>. One needs <a href="https://github.com/rust-analyzer/rust-analyzer/blob/d4cea98bc342b0aa2603106a155722dcbe5534e1/crates/ra_ide_db/src/symbol_index.rs#L114-L132" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/d4cea98bc342b0aa2603106a155722dcbe5534e1/crates/ra_ide_db/src/symbol_index.rs#L114-L132">this trick</a> for it to work with salsa</p>



<a name="189944395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189944395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189944395">(Mar 06 2020 at 23:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Chalk.20solver.20caching/near/189941773" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Chalk.20solver.20caching/near/189941773">said</a>:</p>
<blockquote>
<p>Ie, I am seeing two "name resolution is stuck" errors (and we've recently bumped the limit there a lot)</p>
</blockquote>
<p>it does get past that after some time</p>



<a name="189955765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189955765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189955765">(Mar 07 2020 at 04:09)</a>:</h4>
<blockquote>
<p>Ie, I am seeing two "name resolution is stuck" errors (and we've recently bumped the limit there a lot)</p>
</blockquote>
<p>It seem to relate to <code>include</code> macro , I am investigating now.</p>



<a name="189955808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189955808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189955808">(Mar 07 2020 at 04:10)</a>:</h4>
<p>I saw the same error in my ra-stats tool after my PR.</p>



<a name="189956867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189956867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189956867">(Mar 07 2020 at 04:48)</a>:</h4>
<p>Oh... haha, it is because the <code>include</code> macro expanded correctly, however we have a dummy <code>env</code> macro implementation such that a <code>include!(concat!(env!("OUT_DIR"), "/foo.rs"))</code> will became <code>include!("/foo.rs")</code>, and here  may be a infinite loop. :)</p>



<a name="189957294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/189957294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#189957294">(Mar 07 2020 at 05:06)</a>:</h4>
<p>(<a href="https://github.com/rust-analyzer/rust-analyzer/issues/3508" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/3508">rust-analyzer/rust-analyzer#3508</a>) should fix it.</p>



<a name="190025674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20solver%20caching/near/190025674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20solver.20caching.html#190025674">(Mar 08 2020 at 19:51)</a>:</h4>
<p>Ha, looks like IntelliJ Rust fixed this same exact issue somewhat recently <a href="https://github.com/intellij-rust/intellij-rust/pull/4584" target="_blank" title="https://github.com/intellij-rust/intellij-rust/pull/4584">https://github.com/intellij-rust/intellij-rust/pull/4584</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>